<!-- 新增账户信息 -->
<div class="layuimini-main">

    <div class="layui-form layuimini-form" style="width:96%">
		
        <div class="layui-form-item">
            <label class="layui-form-label required"> 姓名 </label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="name" class="layui-input" />
			</div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label required"> 联系电话 </label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="phone" class="layui-input">
            </div>
        </div>
        
		<div class="layui-form-item">
			<label class="layui-form-label required"> 所属总店</label>
			<div class="layui-input-inline">
				<select name="storeId" id="mainStore" lay-filter="mainStore">
					<option value="">请选择</option>
				</select>
			</div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 分配角色 </label>
		    <div class="layui-input-inline">
		        <select name="roleId" lay-filter="role">
		        	<option value="">-- 请选择 --</option>
					<option value="2">总店管理员</option>
					<option value="3">分店管理员</option>
					<option value="4">检测者</option>
		        </select>
		    </div>
		</div>
		
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save"> 保存 </button>
            </div>
        </div>
    </div>
</div>

<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
			layarea = layui.layarea,
            $ = layui.$;

        //初始化表单，要加上，不然刷新部分组件可能会不加载
        form.render();
		
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
		//自定义验证规则
		form.verify({
			menuName: [/^[a-zA-Z0-9_-]{6,16}$/, '菜单名长度在6-20'],
			menuDesc: [/^[a-zA-Z0-9_-]{6,20}$/, '描述长度在6-20']
		});
		
		layer.ready(function() {
			$.ajax({
				url: 'http://localhost:8004/sccPatient/mainStore',
				type: 'get',
				async: false,
				success: function(result) {
					var data = result.data;
					var mainStore = document.getElementById("mainStore");
					for (var i = 0; i < data.length; i++) {
						var option = document.createElement("option");
						option.setAttribute("value", data[i].storeId);
						console.log(data[i].storeId)
						option.innerText = data[i].storeName;
						mainStore.appendChild(option);
					}
					form.render("select");
				}
			});
		});

        //监听保存按钮事件
        form.on('submit(save)', function (data) {
			//获得表单数据
			var formData = data.field;
			console.log(formData);
			//通过ajax请求提交
			$.ajax({
				url : 'http://localhost:8005/sncUserLogin/ins',
				type: 'post',
				data: JSON.stringify(formData),
				contentType: "application/json;charset=UTF-8",
				success: function(result){
						//刷新页面
						table.reload('currentTableId');
						console.log(result);
				},
				error:function(result){
					console.log(result);
				}
			});
			//关闭弹出层
			layer.close(parentIndex);
            return false;
        });
    });
</script>